﻿using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace SZ.Mech
{
    [HarmonyPatch(typeof(PawnFlyer), "RespawnPawn")]
    public static class PawnFlyer_Patch
    {
        //DamageDef
        public static void Prefix(ref PawnFlyer __instance)//飞行后创建，可以定义个爆炸Def
        {
            JumpExplosionExtension jumpExplosionExtension =  __instance.def.GetModExtension<JumpExplosionExtension>();

            //if (__instance.FlyingPawn.apparel != null)
            //{
            //    foreach (var apparel in __instance.FlyingPawn.apparel.WornApparel)
            //    {
            //        var apparelJump = apparel.def.GetModExtension<JumpExplosionExtension>();
            //        if (apparelJump != null)
            //        {
            //            jumpExplosionExtension = apparelJump;
            //            break;
            //        }
            //    }
            //}

            if (jumpExplosionExtension != null)
            {
                GenExplosion.DoExplosion(__instance.Position, __instance.Map, jumpExplosionExtension.range, jumpExplosionExtension.damage, __instance.FlyingPawn, jumpExplosionExtension.damageAmount, ignoredThings: new List<Thing>() { __instance.FlyingPawn });
            }

            //if (__instance.FlyingPawn.def.defName == "SZ_HeavenForgedBattlefieldDestroyerImitation" || __instance.FlyingPawn.def.defName == "SZ_HeavenForgedBattlefieldDestroyer")
            //{
            //    GenExplosion.DoExplosion(__instance.Position, __instance.Map, 3, SZ_DefOf.SZ_Bomb, __instance.FlyingPawn, 30, ignoredThings: new List<Thing>() { __instance.FlyingPawn });
            //}
        }
    }
}
